package group2assignone.ucm.administrator;

import group2assignone.model.Manager;
import group2assignone.ucm.UCController;
import group2assignone.view.UITool;
import group2assignone.view.administrator.AdminMainView;
import group2assignone.view.administrator.EditManagerView;

/**
 *public class UCEditManager implements UCController
 * this is the class for the use case edit manager
 * it recieves the admin main view as a paramater and opens a view
 * with the manager details displayed and editable
 * @author group2
 */
public class UCEditManager implements UCController {

    // private Manager model;
    private AdminMainView view;
    private Manager man;

    public UCEditManager(AdminMainView a_View) {
        this.view = a_View;
    }

    /**
     * Use Case: Admin main UI
     * Pre-Condition: Add new Manager UI
     * Post-Condition: UI is updated
     * 1. Customer clicks the edit manager button
     * 2. System gathers the selected managers
     * 3. System enters the edit manager view with the manager data
     *
     *
     * 2a. No manager is selected, System displays error and prompts user to
     *      select a manager to edit
     */
    public void run() {


        if (view.getSelectedRow() >= 0) {  //if have selection
            //get view details;
            System.out.println("in edit manager");
            System.out.println("selected row = " + view.getSelectedRow());

            man = new Manager();
            String[] data = view.getRow();
            int index = 0;

            man.setUsername(data[index++]);
            man.setPassword(data[index++]);
            man.setFName(data[index++]);
            man.setLName(data[index++]);
            man.setDob(data[index]);

            view.dispose();
            EditManagerView mView = new EditManagerView(man);
            mView.go();
        } else {
            UITool.displayError("Select a Manager to Edit!!!", view);
        }
    }
}








